<?php

class Application_Form_ProyectosDCCapex extends Sgit_Form
{
    
    public function init_form()
    {
        
         $request = Zend_Controller_Front::getInstance()->getRequest();
         $auth    = Zend_Auth::getInstance()->getIdentity();

         
         $file[1] = Sgit_Util_FileUpload::run('gestion_proyectos','file_noc');
         if(!file_exists($file[1]['dir'])) mkdir($file[1]['dir']);
         
         
         $id=$request->getParam('id');
         
        
        
        
        
         $ref=new Zend_Form_Element_Text('ref');
         $ref ->setLabel('Referencia')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('StringLength', false,array(0, 10));
         $this->addElement($ref);     
          
          
         $proyecto=new Zend_Form_Element_Text('proyecto');
         $proyecto->setLabel('Proyecto')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('StringLength', false,array(0, 255));
         $this->addElement($proyecto);    


        $pep=new Zend_Form_Element_Text('pep');
         $pep ->setLabel('PEP')
                ->setAttrib('size',100)
                ->addFilter('StringTrim')
                ->addValidator('StringLength', false,array(0, 50));       
         $this->addElement($pep);      
         
                
         $dc=new Sgit_Form_Element_Select_Datacenter('id_zona');
         $dc->addFilter('StringTrim')->setRequired(true);
         $this->addElement($dc);
            
               
         $anio=new Sgit_Form_Element_Select_Year('anio');
         $anio->setLabel('Año')
             ->setRequired(true);
         $this->addElement($anio);      
              
              
         $aprobacion=new Sgit_Form_Element_Select_Xml('ProyetosDCAprobado');
         $aprobacion->setLabel('Aprobado Comite')
             ->setRequired(true);
         $this->addElement($aprobacion);      
                   
         $categoria=new Sgit_Form_Element_Select_Xml('ProyetosDCCapexCat');
         $categoria->setLabel('Categoria');
         $this->addElement($categoria);
          

         $importe=new Zend_Form_Element_Text('importe');
         $importe->setLabel('Importe')
                ->addValidator('Int')
                ->addFilter(new Sgit_Filter_Number());
         $this->addElement($importe);      
         
         
         $noc=new Zend_Form_Element_Text('noc');
         $noc->setLabel('Importe NOC')
                ->addValidator('Int')
                ->addFilter(new Sgit_Filter_Number());
         $this->addElement($noc);      
         

        
         $files[0]=new Zend_Form_Element_File($file[1]['name']);
         $files[0]->setLabel('Archivo NOC')
                ->setDestination($file[1]['dir'])
                ->addValidator('Size', false, 31457280)
                ->setValueDisabled(true); 
         $this->addElement($files[0]);


        if($id){
             $options=Sgit_Util_GetFiles::run($file[1]['tabla'],$file[1]['key'],$id);
             
             if($options){
                 $files_lista1 = new Zend_Form_Element_MultiCheckbox($file[1]['activo']);
                 $files_lista1->setMultiOptions($options)
                    ->setLabel('Borrar Adjunto')
                    ->setAttrib('size',25); 
                 $this->addElement($files_lista1);
             }
         }
         


            
         $notas=new Zend_Form_Element_Textarea('notas_capex');
         $notas->setLabel('Notas')
                ->setAttribs(array('rows'=>3,'cols'=>80))
                ->addFilter('StringTrim');
         $this->addElement($notas);    
            

      

  
       $this->setElementDecorators(array(
		    'ViewHelper',
		   'Errors',
		    array(array('data' => 'HtmlTag'),	array('tag' => 'td', 'class' => 'element')   ),
		    array('Label', array('tag' => 'td')),
		    array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
	   ));
       
       
 
          //fix file 
       $files[0]->setDecorators(
            array(
                'File',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td','class' => 'element')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
            )
        );
    



    }
}
